import sys,math
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *

class Drawing(QWidget):
    def __init__(self,parent=None):
        super(Drawing,self).__init__(parent)
        self.initUI()
    def initUI(self):
        self.setGeometry(300,300,280,270)
        self.setWindowTitle("钢笔样式案例")
    def paintEvent(self,e):
        qp=QPainter()
        qp.begin(self)
        self.drawLines(qp)
        qp.end()
    def drawLines(self,qp):
        pen=QPen(Qt.red,2,Qt.SolidLine) #给定线条样式
        qp.setPen(pen)
        qp.drawLine(20,40,200,40)
        pen.setStyle(Qt.DashLine)

        qp.setPen(pen)
        qp.drawLine(20, 80, 200, 80)
        pen.setStyle(Qt.DashDotLine	)

        pen.setStyle(Qt.CustomDashLine)
        pen.setDashPattern([1,4,5,4])#一像素的横线 4像素空余
        qp.setPen(pen)
        qp.drawLine(20,120,200,120)



if __name__ == '__main__':
    app=QApplication(sys.argv)
    demo=Drawing()
    demo.show()
    sys.exit(app.exec_())